﻿namespace WebDevUtilities.Controls
{
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// Interaktionslogik für NumUpDown.xaml
    /// </summary>
    public partial class NumUpDown : UserControl
    {
        private int _numValue = 0;
        public int NumValue
        {
            get { return _numValue; }
            set
            {
                _numValue = value;
                tbNum.Text = value.ToString();
            }
        }
        
        public NumUpDown()
        {
            InitializeComponent();
            tbNum.Text = _numValue.ToString();
        }

        private void tbNum_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!int.TryParse(tbNum.Text, out _numValue))
                tbNum.Text = _numValue.ToString();
        }

        private void btnUp_Click(object sender, RoutedEventArgs e)
        {
            NumValue++;
        }

        private void btnDown_Click(object sender, RoutedEventArgs e)
        {
            if(NumValue > 0)
                NumValue--;
        }
    }
}
